package com.teckteam.ptvsystem.model;

import java.util.ArrayList;

import com.teckteam.ptvsystem.model.facade.PTVSystem;

/**
 * Representation of a result element for the Journey Plan results screen
 *
 */
public class ResultNode
{
   private AbstractStop stop;
   private AbstractRoute route;
   private DepartureTime departTime, arrivalTime;
   private double distance;
   private int hopNumber, carbonUnits;
   
   /**
    * Construct a new result node given results as its instance variables
    * @param stop Name of stop
    * @param route Associated name of the travel path
    * @param time Time this hop is relevant
    * @param distance Length of journey
    * @param hopNumber Hop number 
    * @param carbonUnits Calculated units of carbon based on Transport type
    */
   public ResultNode(AbstractStop stop, AbstractRoute route, DepartureTime departTime,
         DepartureTime arrivalTime, double distance, int i)
   {
      this.stop = stop;
      this.route = route;
      this.departTime = departTime;
      this.arrivalTime = arrivalTime;
      this.distance = distance;
      this.hopNumber = i;
      this.carbonUnits = stop.getCarbonCredits()*(departTime.compareTo(arrivalTime));
   }
   
   /**
    * Compact all details into String array for reading.
    * Format: 
    *    0:hopNumber, 1:stopName, 2:routeName, 3:suburb, 4:timeArrived/Departed, 5:distance(km)
    * 
    * @return
    */
   public String[] getDestinationDetails()
   {
      String details[] = {
            Integer.toString(this.hopNumber),
            stop.toString(),
            route.getRouteName(),
            stop.getSuburb(),
            departTime.toString(),
            arrivalTime.toString(),
            Double.toString(distance),
            Integer.toString(this.carbonUnits)
      };
      
      return details;
   }
   
   /**
    * Returns cumulative travel distance
    */
   public double getDistance()
   {
      return distance;
   }
   
   /**
    * Returns locality coordinates as a string array
    */
   public String[] getCoordinates()
   {
      return stop.getLocality().toArray();
   }
   
   /**
    * Returns associated Carbon credit amount for the journey
    */
   public int getCarbonCredits()
   {
      return carbonUnits;
   }
}
